package cn.itcast.service.company.impl;

import cn.hutool.core.util.IdUtil;
import cn.itcast.dao.company.CompanyDao;
import cn.itcast.domain.company.Company;
import cn.itcast.service.company.CompanyService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class CompanyServiceImpl implements CompanyService {

    @Autowired
    private CompanyDao companyDao;

    @Override
    public List<Company> findAll() {
        return companyDao.findAll();
    }

    @Override
    public Company findById(String id) {
        return companyDao.findById(id);
    }

    @Override
    public void save(Company company) {
        company.setId(IdUtil.simpleUUID());
        companyDao.save(company);

    }

    @Override
    public void update(Company company) {
        companyDao.update(company);
    }

    @Override
    public void delete(String id) {
    companyDao.delete(id);
    }

    @Override
    public PageInfo findByPageHelper(Integer pageNum, Integer pageSize) {
            PageHelper.startPage(pageNum, pageSize);
            List<Company> list = companyDao.findAll();
            return new PageInfo(list,5); //前二后二
        }
    }
